{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "基于上节得到的模型，我们可进一步编写Python代码，对test_x对应的输出数据进行预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import pickle\n",
    "with open('data/model.pkl', 'rb') as f:\n",
    "    model = pickle.load(f)\n",
    "    \n",
    "with open('data/test_x.pkl', 'rb') as f:\n",
    "    test_x = pickle.load(f)\n",
    "    \n",
    "with open('data/t0_min.pkl', 'rb') as f:\n",
    "    t0_min = pickle.load(f)\n",
    "    \n",
    "with open('data/t0_ptp.pkl', 'rb') as f:\n",
    "    t0_ptp = pickle.load(f)\n",
    "    \n",
    "pred_y = model.predict(test_x)\n",
    "pred_y = (pred_y*t0_ptp)+t0_min\n",
    "\n",
    "with open('data/pred_y.pkl', 'wb') as f:\n",
    "    pickle.dump(pred_y, f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如代码所示，将模型的预测结果pred_y乘以t0_ptp再加上t0_min，即可对数据进行还原。pred_y即是最终得到的预测数据，可打印其值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[15.79617574, 17.28782812, 17.03972416, ..., 25.47293619,\n",
       "        21.97720554, 22.11359215],\n",
       "       [18.70329714, 18.99084637, 17.9169553 , ..., 19.56352654,\n",
       "        19.81872964, 20.86391557],\n",
       "       [18.8442563 , 19.07967959, 17.83976497, ..., 22.73882835,\n",
       "        21.23586014, 20.92164919],\n",
       "       ...,\n",
       "       [18.84746295, 17.25980531, 16.04881205, ..., 22.12233859,\n",
       "        20.73743197, 20.18132928],\n",
       "       [15.63063499, 12.58705514, 13.89998444, ..., 19.20242725,\n",
       "        19.7572789 , 19.23616244],\n",
       "       [20.69285267, 20.03131026, 19.14487781, ..., 19.84456904,\n",
       "        17.87872983, 18.55687474]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(30, 96)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred_y.shape"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
